package com.habdqn.jspdemo.im.enetity;

import com.habdqn.jspdemo.im.util.SystemConstant;

import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

/**
 * @author Administrator
 */
public class User implements HttpSessionBindingListener {
    private Integer id;
    private String name;

    public User() {
    }

    public User(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * 当前类的实例对象被放入HttpSession作用域时触发
     * @param event
     */
    @Override
    public void valueBound(HttpSessionBindingEvent event) {
        SystemConstant.ONLINE_USER++;
    }

    /**
     * 当前类的实例对象从HttpSession作用域移除时触发
     * @param event
     */
    @Override
    public void valueUnbound(HttpSessionBindingEvent event) {
        SystemConstant.ONLINE_USER--;
    }
}
